/* 
 * File:   entity_formatter.cpp
 * Author: jolo
 * 
 * Created on: 12. Oktober 2011, 07:00
 * Lincense: New BSD License (The BSD 2-Clause License)
 */

#include "entity_formatter.hpp"
#include <boost/algorithm/string/join.hpp>

#include "widgets/entity_html_viewer.hpp"

#include <model/repository.hpp>
#include <model/project.hpp>
#include <model/chemical_element.hpp>

namespace tools
{

    entity_formatter::entity_formatter()
    {
    }

    entity_formatter::~entity_formatter()
    {
    }

    const string entity_formatter::format(model::entity_ptr e) 
    {
        return e->to_html_page();
    }
    
    const string entity_formatter::make_table(const string_vector& rows) {
        stringstream s;
        s << tag(boost::algorithm::join(rows, "\n"), "table", "border=\"1\"");
        return s.str();
    }
    
    const string entity_formatter::make_page(const string& head, const string& body) {
        stringstream s;
        s << head << body;
        return s.str();
    }
    
    const string entity_formatter::make_head(const string& h)  {
        string t = tag(h, "title");
        return tag(t, "head");
    }
    
    const string entity_formatter::make_body(const string& txt)  {
        return tag(txt, "body");
    }
    
    const string entity_formatter::make_h1(const string& txt)  {
        return tag(txt, "h1");
    }
    
    const string entity_formatter::make_h2(const string& txt)  {
        return tag(txt, "h2");
    }
    
    const string entity_formatter::tag(const string& value, const string& t, const string& args)  {
        stringstream s;
        s << "<" << t << " " << args <<">" << value << "</" << t << ">";
        return s.str();
    }
    
    
}